package com.landian.commons.jpa.criteria;

import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 条件单元容器
 *
 * @author caojl
 * @create 2017/12/14
 **/
public class PredicableContainer {
    /**
     *
     */
    public static PredicableContainer newInstance(){
        return new PredicableContainer();
    }

    /**
     * 条件单元容器
     */
    public List<Predicable> list = new ArrayList<>();


    /**
     * 条件单元
     */
    public PredicableContainer add(Predicable predicable){
        list.add(predicable);
        return this;
    }

    /**
     * 条件单元
     */
    public PredicableContainer add(Predicable... predicableArr){
        if(null != predicableArr){
            for (Predicable predicable : predicableArr) {
                list.add(predicable);
            }
        }
        return this;
    }

    /**
     * 条件单元
     */
    public PredicableContainer add(List<Predicable> list){
        if(CollectionUtils.isNotEmpty(list)){
            for(Predicable predicable : list){
                if(null != predicable){
                    this.list.add(predicable);
                }
            }
        }
        return this;
    }

    /**
     * 返回列表
     */
    public List<Predicable> getList(){
        return list;
    }
}
